package com.z.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.z.admin.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author z
 * @since 2022-02-13
 */
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from t_user t where t.username=#{username}")
    User getUser(String username);

    @Select("select * from t_user t where t.id=#{id}")
    User findUserById(Long id);

    @Select("select * from t_user t")
    List<User> findAll();

    int updateUser(User user);

    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into t_user(username,password,nickname,head_img_url,telephone,phone,email,birthday,sex,status,create_time) values(#{username},#{password},#{nickname},#{headImgUrl},#{telephone},#{phone},#{email},#{birthday},#{sex},#{status},#{createTime})")
    Integer save(User user);

    @Delete("delete from t_user where id=#{id}")
    void delete(Long id);

    @Select("select count(*) from t_user")
    Integer conutAllUsers();

    @Select("select * from t_user t order by t.id limit #{startPosition} , #{limit}")
    List<User> findUserByPage(@Param("startPosition") Integer startPosition, @Param("limit") Integer limit);

    @Select("select * from t_user where phone = #{phone}")
    List<User> findUserByPhone(String phone);

    @Select("select count(*) from t_user ${whereSql}")
    Integer conutByMap(String whereSql);

    @Select("select * from t_user t ${where} order by t.id limit #{startPosition} , #{limit}")
    List<User> findPageByWhereSql(String where, Integer startPosition, Integer limit);
}
